//
//  ChannelNum.m
//  DianNaoWang
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "Type6ThreeImageCell.h"

#import "UIImageView+WebCache.h"
@implementation Type6ThreeImageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatViews];
    }
    return self;
}
-(void)creatViews
{
    _titleLabel = [[UILabel alloc]init];
    
    _titleLabel.font = contentTextSize;
    _titleLabel.numberOfLines = 0;
    [self.contentView addSubview:_titleLabel];

    
    _leftImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_leftImageView];

    
    _midImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_midImageView];

    
    _rightImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_rightImageView];

    
    _dataLabel = [[UILabel alloc]init];
    _dataLabel.textColor = otherTextColor;
    _dataLabel.font = otherTextSize;
    [self.contentView addSubview:_dataLabel];

    
    _pic_numLabel = [[UILabel alloc]init];
    _pic_numLabel.textColor = otherTextColor;
    _pic_numLabel.font = otherTextSize;
    [self.contentView addSubview:_pic_numLabel];

    
    _coment_numLabel = [[UILabel alloc]init];
    _coment_numLabel.textColor = otherTextColor;
    _coment_numLabel.font = otherTextSize;
    [self.contentView addSubview:_coment_numLabel];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    _titleLabel.textColor = contenttextColor;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:contentTextSize, NSFontAttributeName, nil];
    CGRect rect = [_titleLabel.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20 * FitWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _titleLabel.frame = CGRectMake(10 *FitWidth, 10 *FitHeight, ScreenWidth - 20 * FitWidth, rect.size.height);
    NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:otherTextSize, NSFontAttributeName, nil];
    CGRect rect2 = [_coment_numLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20 * FitHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil];
    CGRect rect3 = [_pic_numLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20 * FitHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic2 context:nil];
    
    _leftImageView.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.origin.y + _titleLabel.frame.size.height + 10 * FitHeight, 111 * FitWidth, 90 * FitHeight);
    _midImageView.frame = CGRectMake(_leftImageView.frame.origin.x + _leftImageView.frame.size.width + 11 * FitWidth, _leftImageView.frame.origin.y, _leftImageView.frame.size.width, _leftImageView.frame.size.height);
    _rightImageView.frame = CGRectMake(_midImageView.frame.origin.x + _midImageView.frame.size.width + 11 * FitWidth, _midImageView.frame.origin.y, _midImageView.frame.size.width, _midImageView.frame.size.height);
    
    _dataLabel.frame = CGRectMake(_leftImageView.frame.origin.x, _leftImageView.frame.origin.y + _leftImageView.frame.size.height + 10 * FitHeight, 100 * FitWidth, 20 * FitHeight);
    
    _coment_numLabel.frame = CGRectMake(ScreenWidth - 10 * FitWidth - rect2.size.width, _dataLabel.frame.origin.y + 5 * FitHeight, rect2.size.width, 10 * FitHeight);
    _pic_numLabel.frame = CGRectMake(ScreenWidth - 10 * FitWidth - _coment_numLabel.frame.size.width - rect3.size.width - 10 * FitWidth, _dataLabel.frame.origin.y, rect3.size.width, 20 * FitHeight);
}
-(void)setChannelList:(ChannelList *)channelList
{
    if (_channelList != channelList) {
        _channelList = channelList;
    }
    _titleLabel.text = channelList.stitle;
    switch (channelList.pics.count) {
        case 1:
            [_leftImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[0]] placeholderImage:[UIImage imageNamed:@"123"]];
        case 2:
            [_leftImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[0]] placeholderImage:[UIImage imageNamed:@"123"]];
            [_midImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[1]] placeholderImage:[UIImage imageNamed:@"123"]];
            break;
        default:
            [_leftImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[0]] placeholderImage:[UIImage imageNamed:@"123"]];
            [_midImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[1]] placeholderImage:[UIImage imageNamed:@"123"]];
            [_rightImageView sd_setImageWithURL:[NSURL URLWithString:channelList.pics[2]] placeholderImage:[UIImage imageNamed:@"123"]];
            break;
    }
    _dataLabel.text = [channelList.sdate substringFromIndex:5];
    _pic_numLabel.text = [NSString stringWithFormat:@"%ld 图", channelList.pic_num];
    
    //判断评论数为0时显示"抢沙发"
    if (channelList.comment_num != 0) {
        NSString *str = [NSString stringWithFormat:@"%ld 评论", channelList.comment_num];
        _coment_numLabel.text = str;
    }else{
        _coment_numLabel.text = @"抢沙发";
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
